<?php
require_once('../autoload.php');

try {

	if (isset($_GET['id'])
	    && isset($_GET['lang'])
		&& file_exists($xmlPath = '../assets/xml/' . $_GET['id'] . '.xml')
		&& false !== ($config = simplexml_load_file($xmlPath))
	) {
	
		$config->lang = $_GET['lang'];
		$config = get_object_vars($config);
		
		$header = Tv_Arte_Header::getInstance($config);
		$view = new Tv_Arte_View();
		$view->assign('config', 	$header->getConfig())
			->assign('showLang', 	$header->getShowLang())
			->assign('showLogin', 	$header->getShowLogin())
			->assign('showSocial', 	$header->getShowSocial())
			->assign('current', 	$header->getCurrent())
			->assign('langs', 		$header->getLanguages())
			->assign('xml', 		$config)
			->assign('lang', 		$header->getLang());
		
		print $view->render('../tpl/render-index.php');
		
	}
	
} catch (Tv_Arte_Header_Exception $e) {
	print $e->getMessage();
}